package com.h2.gwt.util.adapt;


/**
 * TODO_DOCUMENT_ME
 * 
 */
public final class AdaptUtils {
   
   private AdaptUtils() {
      //utility constructor
   }
   
   public static Object adaptToClass(Object adaptableObject, Class<?> clz) {
      String strVal = (String)adaptableObject;
      
      if(strVal == null) {
         //do not throw NullPointerException
         return null;
      }
      else if (clz.equals(Integer.class)) {
         return new Integer(strVal);
      }
      else if (clz.equals(Long.class)) {
         return new Long(strVal);
      }
      else if (clz.equals(Short.class)) {
         return new Short(strVal);
      }
      else if (clz.equals(Byte.class)) {
         return new Byte(strVal);
      }
      else if (clz.equals(Float.class)) {
         return new Float(strVal);
      }
      else if (clz.equals(Double.class)) {
         return new Double(strVal);
      }
      else if (clz.equals(CharSequence.class)) {
         return adaptableObject;
      }
      else if (clz.equals(String.class)) {
         return adaptableObject;
      }
      else if (clz.equals(Boolean.class)) {
         return Boolean.parseBoolean(strVal);
      }
      return null;
   }
   
}
